﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using NetBay.Core.BusinessEntities;
using RIOWCFSERVICE = Rio.Framework.WCFService.RioWcfServices;
using Rio.Framework.Pages.Controls;

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class OCRMaskChildWindow : ChildWindow
    {
        #region Attribute
        #region Private
        private List<RIOWCFSERVICE.ImageRio> m_oSelectedThumbNails;
        private List<OcrMask> m_oOcrMaskList;
        private ObservableCollection<OCRThumbBox> m_oOcrThumbBoxList = new ObservableCollection<OCRThumbBox>();
        #endregion 

        #region Public
        public List<string> OcrThumbNailNameList { get; set; }
        public List<long> OcrMaskList { get; set; }
        #endregion
        #endregion

        #region Init/Constructor
        public OCRMaskChildWindow()
        {
            InitializeComponent();
            this.KeyUp += MessageBoxChildWindow_KeyUp;
            OcrThumbNailNameList = new List<string>();
            OcrMaskList = new List<long>();
        }

        public OCRMaskChildWindow(List<RIOWCFSERVICE.ImageRio> P_oSelectedThumbNails, List<OcrMask> P_oOcrMaskList)
            : this()
        {
            m_oSelectedThumbNails = P_oSelectedThumbNails;
            m_oOcrMaskList = P_oOcrMaskList;

            SetBindingListThumbBox();
        }
        #endregion

        #region Function

        private void MessageBoxChildWindow_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
            }
        }

        /// <summary>
        /// Databind thumbbox control
        /// </summary>
        private void SetBindingListThumbBox()
        {
            foreach (RIOWCFSERVICE.ImageRio L_oImgRio in m_oSelectedThumbNails)
            {
                m_oOcrThumbBoxList.Add(new OCRThumbBox(L_oImgRio, m_oOcrMaskList));
            }

            ListThumbBox.ItemsSource = m_oOcrThumbBoxList;
        }


        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (OCRThumbBox L_oOcrThumbBox in m_oOcrThumbBoxList)
            {
                List<OcrMaskBox> L_oOcrMaskBoxList = L_oOcrThumbBox.DynamicCheckBox.ItemsSource as List<OcrMaskBox>;

                foreach (OcrMaskBox L_oOcrMaskBox in L_oOcrThumbBox.DynamicCheckBox.Items)
                {
                    if (L_oOcrMaskBox.IsChecked == true)
                    {
                        OcrMaskList.Add(L_oOcrMaskBox.OcrMaskItem.Identifier);
                        OcrThumbNailNameList.Add(L_oOcrThumbBox.GetImageRioName());
                    }
                }
            }

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        #endregion
    }
}

